<?php
/*
 * Copyright notice
 * 
 * (c) 2009 MH-Dev.de, Martin Hesse <info@mh-dev.de>
 * 
 * This script is part of the MH-Dev.-Board project. The MH-Dev.-Board 
 * is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, 
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU 
 * General Public License along with this program; if not, 
 * see http://www.gnu.org/licenses/.
 */

class MHDEV_View_Helper_GetBoardVisitors extends Zend_View_Helper_Abstract
{
	/*
	 * Get all current visitor of a board
	 * 
	 * @param int board_uid
	 * 
	 * @return mixed false or a list with all user
	 */
    public function GetBoardVisitors($uid)
    {
    	// vars
    	$content		= FALSE;
    	$separator		= ', ';
    	$i				= 1;
    	
    	// helper
    	$author			= new MHDEV_View_Helper_GetAuthor();
    	$url			= new Zend_View_Helper_Url();
    	
    	// db
    	$userOnline		= new UserOnline();
    	
    	// query
    	$getUserOnline	= $userOnline->fetchAll('`user_uid` > 0 AND `board_uid`=' . intval($uid));
    	
    	if($getUserOnline->count() > 0)
    	{
    		foreach($getUserOnline->toArray() AS $user)
    		{
    			$profile_url	= $url->url(array(
    				'controller'	=> 'profile',
    				'uid'			=> $user['user_uid']
    			), 'profile', true);
    			
    			$content		.= '<a class="board_visitor" href="' . $profile_url . '">';
    			$content 		.= $author->GetAuthor($user['user_uid']);
    			$content		.= '</a>';
    			
    			if($i<$getUserOnline->count())
    			{
    				$content .= $separator;
    			}
    			
    			$i++;
    		}
    	}
    	
    	$this->view->content	= $content;
    	
		return $this->view->render('helper/GetBoardVisitors.phtml');
    }
}
?>